package com.leshua.channel.mpos.service.mpos.impl;

import com.leshua.channel.mpos.mapper.mpos.MposAgentWhiteListMapper;
import com.leshua.channel.mpos.model.lepos.MerchantTmp;
import com.leshua.channel.mpos.model.mpos.MposAgentWhiteList;
import com.leshua.channel.mpos.model.mpos.MposAgentWhiteListExample;
import com.leshua.channel.mpos.service.lepos.MerchantTmpService;
import com.leshua.channel.mpos.service.mpos.MposAgentWhiteService;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;

@Service
public class MposAgentWhiteServiceImpl implements MposAgentWhiteService {

    /**
     * 白名单类型:1-支付宝
     */
    private static final Integer TYPE_ZFB = 1;

    @Resource
    private MerchantTmpService merchantTmpService;

    @Resource
    private MposAgentWhiteListMapper agentWhiteListMapper;

    @Override
    public boolean canScanPay(String merchantId) {
        MerchantTmp merchantTmp = merchantTmpService.queryMerchant(merchantId);
        if (merchantTmp == null) {
            return false;
        }
        Integer agentId1g = merchantTmp.getAgentId1g();
        MposAgentWhiteListExample example = new MposAgentWhiteListExample();
        MposAgentWhiteListExample.Criteria criteria = example.createCriteria();
        criteria.andAgentIdEqualTo(String.valueOf(agentId1g));
        criteria.andTypeEqualTo(TYPE_ZFB);
        List<MposAgentWhiteList> agentWhiteLists = agentWhiteListMapper.selectByExample(example);
        if (CollectionUtils.isEmpty(agentWhiteLists)) {
            return false;
        }
        return true;
    }
}
